<template>
  <div class="auth-page">
    <div class="container page">
      <div class="row">

        <div class="col-md-6 offset-md-3 col-xs-12">
          <h1 class="text-xs-center">Sign up</h1>
          <p class="text-xs-center">
              <a href="">Have an account?</a>
          </p>

          <ul class="error-messages">
              <li>That email is already taken</li>
          </ul>

          <form @submit.prevent="onSubmit">
              <fieldset class="form-group">
                  <input class="form-control form-control-lg" v-model="user.username" type="text" placeholder="Your Name">
              </fieldset>
              <fieldset class="form-group">
                  <input class="form-control form-control-lg"  v-model="user.email" type="text" placeholder="Email">
              </fieldset>
              <fieldset class="form-group">
                  <input class="form-control form-control-lg"  v-model="user.password" type="password" placeholder="Password">
              </fieldset>
              <button class="btn btn-lg btn-primary pull-xs-right">
                  Sign up
              </button>
          </form>
        </div>

      </div>
    </div>
  </div>
</template>


<script lang='ts'>
import Vue from 'vue'

import { register } from '@/api/auth'
export default Vue.extend({
  name: 'LoginIndex',
  data () {
    return {
      user: {
        username: '',
        email: '',
        password: ''
      }
    }
  },
  methods: {
    async onSubmit () {
      try {
        const data = await register({
          user: this.user
        })

        this.$router.push({
          name: 'home'
        })
      } catch (e) {
        console.log('注册失败...', e)
      }
    }
  }
})
</script>

<style>

</style>